home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Cappuccino / Source / CappuccinoUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-11  |  7.9 KB  |  306 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CappuccinoUtils.h
  3.  
  4.     Contains:    Cappuccino utility functions & classes
  5.  
  6.     Written by:    Steve Smith and Troy Gaul
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11.  
  12. #ifndef _CAPPUCCINOUTILS_
  13. #define _CAPPUCCINOUTILS_
  14.  
  15. // --- OpenDoc Includes ---
  16.  
  17. #ifndef _ODTYPES_
  18. #include <ODTypes.h>
  19. #endif
  20.  
  21. // --- OpenDoc Utilities ---
  22.  
  23. #ifndef _ITEXT_
  24. #include <IText.h>            // for ODScriptCode and ODLangCode
  25. #endif
  26.  
  27. // --- Macintosh Includes ---
  28.  
  29. #ifndef __DIALOGS__
  30. #include <Dialogs.h>        // for DialogPtr
  31. #endif
  32.  
  33. //------------------------------------------------------------------------------
  34. // ODOptVirtual
  35. //    This preprocessor symbol is used to control the use of virtual functions
  36. //    for this class.  It can be set to "virtual" if you want to have a class
  37. //    where any of the functions may be overridden.
  38. //------------------------------------------------------------------------------
  39.  
  40. #ifndef ODOptVirtual
  41. #define ODOptVirtual
  42. #endif
  43.  
  44. //------------------------------------------------------------------------------
  45. // Forward Declarations
  46. //------------------------------------------------------------------------------
  47.  
  48. class ODDraft;
  49. class ODFacet;
  50. class ODFocusSet;
  51. class ODWindow;
  52. class ODSession;
  53. class ODStorageUnit;
  54. class ODStorageUnitView;
  55.  
  56. //------------------------------------------------------------------------------
  57. // Function Prototypes
  58. //------------------------------------------------------------------------------
  59.  
  60. ODIText*        GetPartName(Environment* ev, ODPart* part, ODType category);
  61. ODBoolean        NamesAreEquivalent(Environment* ev, ODIText* fileName,
  62.                                         ODIText* partName);
  63. void            GetEditorScriptLanguage(Environment* ev, ODScriptCode* script,
  64.                                         ODLangCode* language);
  65. void            FixedToIntRect(ODRect& fixedRect, Rect& intRect);
  66. void            IntToFixedRect(Rect& intRect, ODRect& fixedRect);
  67. void            LoadThumbnail(Environment* ev, Handle* thumbnail);
  68. Rect            TilePartWindow(Environment* ev, Rect* facetBounds,
  69.                                         Rect* partWindowBounds);
  70. ODUShort        CountFacets(Environment* ev, ODFrame* frame);
  71. ODBoolean        HasAnyFocusInSet(Environment* ev, ODFrame* frame, 
  72.                                         ODFocusSet* set);
  73.  
  74. void            SetPreferredKind(Environment* ev, ODStorageUnit* su,
  75.                                         ODValueType kind);
  76. ODISOStr        DuplicateISOStr(ODISOStr string);
  77.  
  78. ODBoolean        HasSpeech();
  79. void            SetDialogDefaults(DialogPtr dialog, ODUShort finfID, 
  80.                                         ODUShort index);
  81. pascal ODBoolean IntegerDialogFilter(DialogPtr dialog, EventRecord* event,
  82.                                         short* itemHit);
  83.  
  84. //==============================================================================
  85. // Utility Class Definitions
  86. //==============================================================================
  87.  
  88. //------------------------------------------------------------------------------
  89. // CTempDialogState
  90. //------------------------------------------------------------------------------
  91.  
  92. class CTempDialogState : Destructo {
  93.  
  94. public:
  95.     CTempDialogState(Environment *ev, ODSession *session);
  96.     ~CTempDialogState();
  97.     
  98.     DialogPtr CreateDialog(ODSShort resID);
  99.  
  100. private:
  101.     Environment*    fEv;
  102.     ODSession*        fSession;
  103.     DialogPtr        fDialogPtr;
  104.     ODSLong            fResRefNum;
  105. };
  106.  
  107. //------------------------------------------------------------------------------
  108. // CFrameProxy        (aka CFuton)
  109. //------------------------------------------------------------------------------
  110.  
  111. class CFrameProxy {
  112.  
  113. public:
  114.  
  115.     CFrameProxy();
  116.     ~CFrameProxy();
  117.     
  118.     void        InitFrameProxy(ODID frameID, ODDraft* draft);
  119.     void        InitFrameProxy(Environment* ev, ODFrame* frame);
  120.     void        Purge(Environment* ev);
  121.  
  122.     ODFrame*    GetFrame(Environment* ev);
  123.     void        SetFrame(Environment* ev, ODFrame* frame);
  124.     ODBoolean    FrameIsLoaded(Environment* ev);
  125.     ODID        GetID();
  126.     ODDraft*    GetDraft();
  127.     
  128. private:
  129.  
  130.     ODFrame*    fFrame;
  131.     ODDraft*    fDraft;
  132.     ODID        fID;
  133. };
  134.  
  135. //------------------------------------------------------------------------------
  136. // CFrameInfo
  137. //------------------------------------------------------------------------------
  138.  
  139. class CFrameInfo {
  140.  
  141. public:
  142.                             CFrameInfo(ODSession* session);
  143.     ODOptVirtual             ~CFrameInfo();
  144.     
  145.     // -- I/O --
  146.     
  147.     ODOptVirtual void        Externalize(Environment* ev, 
  148.                                     ODStorageUnitView* storageUnitView);
  149.     ODOptVirtual void        CleanseFrameInfoProperty(Environment* ev, 
  150.                                     ODStorageUnit* storageUnit);
  151.     ODOptVirtual void        ExternalizeFrameInfo(Environment* ev, 
  152.                                     ODStorageUnit* storageUnit,
  153.                                     ODDraftKey key, ODFrame* scopeFrame);
  154.     ODOptVirtual void        CloneInto(Environment *ev, ODDraftKey key,
  155.                                     ODStorageUnitView* storageUnitView,
  156.                                     ODFrame* scopeFrame);
  157.     ODOptVirtual void        InitFromStorage(Environment* ev, 
  158.                                     ODStorageUnitView* storageUnitView);
  159.     
  160.     // -- Frame activation --
  161.     
  162.     ODOptVirtual ODBoolean    IsFrameActive();
  163.     ODOptVirtual void        SetFrameActive(ODBoolean active);
  164.     ODOptVirtual ODBoolean    FrameNeedsReactivating();
  165.     ODOptVirtual void        SetFrameReactivate(ODBoolean reactivate);
  166.     
  167.     // -- Facet activation --
  168.     
  169.     ODOptVirtual ODFacet*    GetActiveFacet();
  170.     ODOptVirtual void        SetActiveFacet(ODFacet* facet);
  171.     
  172.     // -- Source frame --
  173.     
  174.     ODOptVirtual ODBoolean    HasSourceFrame();
  175.     ODOptVirtual void        SetSourceFrame(Environment* ev, ODFrame* frame);
  176.     ODOptVirtual ODFrame*    GetSourceFrame(Environment* ev);
  177.     ODOptVirtual void        ReleaseSourceFrame(Environment* ev);
  178.     
  179.     // -- Dependent frame --
  180.     
  181.     ODOptVirtual ODBoolean    HasDependentFrame();
  182.     ODOptVirtual void        SetDependentFrame(Environment* ev, ODFrame* frame);
  183.     ODOptVirtual ODFrame*    GetDependentFrame(Environment* ev);
  184.     ODOptVirtual void        ReleaseDependentFrame(Environment* ev);
  185.     
  186.     // -- Part window --
  187.     
  188.     ODOptVirtual ODWindow*    AcquirePartWindow(Environment* ev);
  189.     ODOptVirtual void        SetPartWindow(Environment* ev, ODWindow* window);
  190.     
  191.     // -- Window disposal --
  192.     
  193.     ODOptVirtual void        SetShouldDisposeWindow(ODBoolean should);
  194.     ODOptVirtual ODBoolean    ShouldDisposeWindow();
  195.     
  196.     // -- Part Info --
  197.     
  198.     static CFrameInfo*        GetFrameInfo(Environment* ev, ODFrame* frame);
  199.     static CFrameInfo*        GetFrameInfo(Environment* ev, ODFacet* facet);
  200.     
  201. private:
  202.     
  203.     CFrameInfo(); // don't want parts to call
  204.     
  205.     ODSession*        fSession;
  206.     ODFacet*        fActiveFacet;
  207.     CFrameProxy*    fSourceFrame;
  208.     CFrameProxy*    fDependentFrame;
  209.     ODID            fPartWindowID;
  210.     ODBoolean        fFrameActive;
  211.     ODBoolean        fFrameReactivate;
  212.     ODBoolean        fShouldDisposeWindow;
  213. };
  214.  
  215. //==============================================================================
  216. // Inline methods
  217. //==============================================================================
  218.  
  219. //------------------------------------------------------------------------------
  220. // CFrameProxy
  221. //------------------------------------------------------------------------------
  222.  
  223. inline CFrameProxy::CFrameProxy()
  224. {
  225.     fFrame    = kODNULL;
  226.     fID        = kODNULLID;
  227.     fDraft    = kODNULL;
  228. }
  229.  
  230. inline ODID CFrameProxy::GetID()
  231. {
  232.     return fID;
  233. }
  234.  
  235. inline ODDraft* CFrameProxy::GetDraft()
  236. {
  237.     return fDraft;
  238. }
  239.  
  240. //-------------------------------------------------------------------------
  241. // CFrameInfo
  242. //-------------------------------------------------------------------------
  243.  
  244. inline ODBoolean CFrameInfo::IsFrameActive()
  245. {
  246.     return fFrameActive;
  247. }
  248.  
  249. inline void CFrameInfo::SetFrameActive(ODBoolean active)
  250. {
  251.     fFrameActive = active;
  252. }
  253.  
  254. inline ODBoolean CFrameInfo::FrameNeedsReactivating()
  255. {
  256.     return fFrameReactivate;
  257. }
  258.  
  259. inline void CFrameInfo::SetFrameReactivate(ODBoolean reactivate)
  260. {
  261.     fFrameReactivate = reactivate;
  262. }
  263.  
  264. inline ODFacet* CFrameInfo::GetActiveFacet()
  265. {
  266.     return fActiveFacet;
  267. }
  268.  
  269. inline void CFrameInfo::SetActiveFacet(ODFacet* facet)
  270. {
  271.     fActiveFacet = facet;
  272. }
  273.  
  274. inline ODFrame* CFrameInfo::GetSourceFrame(Environment* ev)
  275. {
  276.     return fSourceFrame->GetFrame(ev);
  277. }
  278.  
  279. inline ODBoolean CFrameInfo::HasSourceFrame()
  280. {
  281.     return (fSourceFrame != kODNULL);
  282. }
  283.  
  284. inline ODFrame* CFrameInfo::GetDependentFrame(Environment* ev)
  285. {
  286.     return fDependentFrame->GetFrame(ev);
  287. }
  288.  
  289. inline ODBoolean CFrameInfo::HasDependentFrame()
  290. {
  291.     return (fDependentFrame != kODNULL);
  292. }
  293.  
  294. inline void CFrameInfo::SetShouldDisposeWindow(ODBoolean should)
  295. {
  296.     fShouldDisposeWindow = should;
  297. }
  298.  
  299. inline ODBoolean CFrameInfo::ShouldDisposeWindow()
  300. {
  301.     return fShouldDisposeWindow;
  302. }
  303.  
  304. #endif
  305.  
  306.